<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
jimport( 'joomla.application.component.view' );

class JAJobBoardViewJAFeeds extends JAView
{
    /**
     * Display the view
     */
    function display($tmpl = null)
    {
    	global $option;
    	$task = JRequest::getVar("task", '');
		switch ($task){
			case 'add':
			case 'edit':				
				JAJobBoardViewJAFeeds::displayForm();
				break;			
			default:
				JAJobBoardViewJAFeeds::displayListItems();
		}
		
		parent::display($tmpl);
  	}
  	
  	
  	/**
  	* Display List of items
  	*/
  	function displayListItems(){  		
  		global $mainframe, $option;        
        $items		= & $this->get( 'Items');
		$pagination = & $this->get( 'Pagination' );
		
		$this->assignRef('items',		$items);
		$this->assignRef('pagination',	$pagination);
  	}
  	/**
  	* Display edit form
  	*/
  	function displayForm(){  	    
  		global $option,$jbconfig;
  		$this->setLayout('form');
  		$feed =& $this->get('Item');
  		if (JRequest::getVar('postback',false))
  		{
  			$post    = JRequest::get('request', JREQUEST_ALLOWHTML);
            $feed->bind($post);
  		}
		$isNew = ($feed->id<1);
		
		
		$lists = array();
		
		if ($isNew)  {
			$default =& $this->get('DefaultData');			
		} else {
			// for existing items the button is renamed `close`
			
		}
		
		
		//rss type list
		$rssType[] = JHTML::_('select.option', '0.91','RSS 0.91');
		$rssType[] = JHTML::_('select.option', '1.0','RSS 1.0');
		$rssType[] = JHTML::_('select.option', '2.0','RSS 2.0');
		$rssType[] = JHTML::_('select.option', "MBOX","MBOX");
		$rssType[] = JHTML::_('select.option', "OPML","OPML");
		$rssType[] = JHTML::_('select.option', "ATOM","ATOM");
		$rssType[] = JHTML::_('select.option', "ATOM0.3","ATOM 0.3");
		$rssType[] = JHTML::_('select.option', "HTML","HTML");
		$rssType[] = JHTML::_('select.option', "JS","JS");
		$lists['rssTypeList'] = JHTML::_('select.genericlist', $rssType, 'feed_type', 'class="inputbox"', 'value', 'text', $isNew ? $jbconfig['feeds']->get('defaultType') : $feed->feed_type, 'feed_type');

		$fulltext[] = JHTML::_('select.option', "0","Do nothing");
		$fulltext[] = JHTML::_('select.option', "1","Read more link");
		$fulltext[] = JHTML::_('select.option', "2","Add to intro text");
		$lists['fulltextlist'] = JHTML::_('select.genericlist', $fulltext, 'msg_fulltext', 'class="inputbox"', 'value', 'text',  $isNew ? '1': $feed->msg_fulltext );
		
		$orderings[] = JHTML::_('select.option', 'date','Date Ascending');
		$orderings[] = JHTML::_('select.option', 'rdate','Date Descending');
		$lists['orderingList'] = JHTML::_('select.genericlist', $orderings, 'msg_orderby', 'class="inputbox"', 'value', 'text', $isNew ? $jbconfig['feeds']->get('orderby') : $feed->msg_orderby, 'msg_orderby');
		
		$numWords[] = JHTML::_('select.option','0','All');
		for ($i=25;$i<=250;$i+=25) {
			$numWords[] = JHTML::_('select.option',$i,$i);
		}
		$lists['numWordsList'] = JHTML::_('select.genericList', $numWords, 'msg_numWords', 'class="inputbox"','value', 'text', $isNew ? $jbconfig['feeds']->get('numWords') : $feed->msg_numWords, 'msg_numWords' );
		
		$authorformats[] = JHTML::_( 'select.option', 'NAME','Name Only');
		$authorformats[] = JHTML::_( 'select.option', 'EMAIL','Email Only');
		$authorformats[] = JHTML::_( 'select.option', 'NAME-EMAIL','Name and Email');
		$lists['renderAuthorList'] = JHTML::_('select.genericList', $authorformats, 'feed_renderAuthorFormat', 'class="inputbox"','value', 'text', $isNew ? $jbconfig['feeds']->get('renderAuthorFormat') : $feed->feed_renderAuthorFormat, 'feed_renderAuthorFormat' );
		
		$renderHTML[] = JHTML::_( 'select.option', '1','Yes');
		$renderHTML[] = JHTML::_( 'select.option', '0','No');
		$lists['renderHTMLList'] =JHTML::_( 'select.genericList',$renderHTML, 'feed_renderHTML', 'class="inputbox"','value', 'text', $isNew ? $jbconfig['feeds']->get('renderHTML') : $feed->feed_renderHTML , 'feed_renderHTML');
		
		
		$renderImages[]   = JHTML::_( 'select.option', "1","Yes");
		$renderImages[]   = JHTML::_( 'select.option', "0","No");
		$lists['renderImagesList'] = JHTML::_( 'select.genericList', $renderImages, 'feed_renderImages', 'class="inputbox"','value', 'text',$isNew ? '1' : $feed->feed_renderImages );
	
		$renderPubl[] = JHTML::_( 'select.option', "1","Yes");
		$renderPubl[] = JHTML::_( 'select.option', "0","No");
		$lists['renderPublishedList'] = JHTML::_( 'select.genericList', $renderPubl, 'published', 'class="inputbox"','value', 'text',$isNew ? NULL : $feed->published);
//		Filter feeds - begin -		
		$value_Location = getItemByFieldName('ja_location','','');
		$option_Location = array();
		$option_Location[] = JHTML::_('select.option','',JText::_('All'));
		if($isNew)
			$locationSelected = '';
		else
			if (!is_array($feed->filter_location_id))
				$locationSelected = explode(',',$feed->filter_location_id);
			else 
				$locationSelected = $feed->filter_location_id;
		if (is_array($value_Location))
		{
			foreach ($value_Location as $location)
				$option_Location[] = JHTML::_('select.option',$location->id,$location->name);
		}
		$lists['filter_location_id'] = JHTML::_( 'select.genericList',$option_Location, 'filter_location_id' . '[]', ' style="width:200px" size="10" class="inputbox"  multiple="true"', 'value', 'text', $locationSelected );
		
		$value_cat = getItemByFieldName('ja_categories','','');
		$option_Cat = array();
		$option_Cat[] = JHTML::_('select.option','',JText::_('All'));
		if($isNew)
			$catSelected = '';
		else
			if (!is_array($feed->filter_cat_id))
				$catSelected = explode(',',$feed->filter_cat_id);
			else 
				$catSelected = $feed->filter_cat_id;
		if (is_array($value_cat))
		{
			foreach ($value_cat as $cat)
				$option_Cat[] = JHTML::_('select.option',$cat->id,$cat->name);
		}
		$lists['filter_cat_id'] = JHTML::_( 'select.genericList',$option_Cat, 'filter_cat_id' . '[]', ' style="width:200px" size="10" class="inputbox"  multiple="true"', 'value', 'text', $catSelected );
		
//		Filter feeds - end -
		
		
		//Feedbutton images uit de directory laden
		$button_path = JPATH_ROOT .DS. "components".DS."com_jajobboard".DS."views".DS."jafeeds".DS."images".DS."buttons";
		$dir = @opendir($button_path);
		$button_images = array();
		$button_col_count = 0;
		$buttons[] = JHTML::_( 'select.option', "", "--Select--");
		while( $file = @readdir($dir) )
		{
			if( $file != '.' && $file != '..' && is_file($button_path . '/' . $file) && !is_link($button_path . '/' . $file) )
			{
				if( preg_match('/(\.gif$|\.png$|\.jpg|\.jpeg)$/is', $file) )
				{
				   $button_images[$button_col_count] = $file;
				   $button_name[$button_col_count] = ucfirst(str_replace("_", " ", preg_replace('/^(.*)\..*$/', '\1', $file)));
				   $buttons[] = JHTML::_( 'select.option', $button_images[$button_col_count], $button_name[$button_col_count]);
				   $button_col_count++;				
				}
			}
		}
		@closedir($dir);
		$lists['feedButtons'] = JHTML::_( 'select.genericList', $buttons, 'feed_button', 'onchange="loadButton(this)" class="inputbox" ','value', 'text',$isNew ? 'rss20.gif' : $feed->feed_button);
		
		//Editor
		$editor  =& JFactory::getEditor();	
		
		$this->assignRef('id', $feed->id);
		$this->assignRef('is_user', $feed->is_user);
		$this->assignRef('name', $feed->feed_name);
		$this->assignRef('alias', $feed->feed_alias);
		$this->assignRef('count', $feed->msg_count = $isNew? $jbconfig['feeds']->get('count'):$feed->msg_count);
		$this->assignRef('cache', $feed->feed_cache = $isNew? $jbconfig['feeds']->get('cache'):$feed->feed_cache);
		$this->assignRef('imgUrl', $feed->feed_imgUrl);
		$isNew? $feed->feed_button='rss20.gif':$feed->feed_button;
		$this->assignRef('BtnImgUrl', $feed->feed_button);
		$this->assignRef('exitems', $feed->filter_exitems);
		$this->assignRef('exemployers', $feed->filter_exemployers);
		$this->assignRef('inemployers', $feed->filter_inemployers);
		$this->assignRef('description', $feed->feed_description);
		$this->assignRef('editor', $editor);
		$this->assignRef('lists', $lists);
		$this->assignRef('feed',$feed);
	
  	   
	}
	
	function getFeedTabs(){
		global $option;
  		$type = JRequest::getVar('tab','feedlist');
  		$tabs = '<div class="submenu-box">
						<div class="submenu-pad">
							<ul id="submenu" class="configuration">';
  		
  		$tabs.= '<li><a href="index.php?option='.$option.'&view=jafeeds&tab=feedlist"';
		if ($type == 'feedlist') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Sample feeds' ).'</a></li>';
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jafeeds&tab=userlist"';
		if ($type == 'userlist') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'User created feeds' ).'</a></li>';
  		
  		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=feeds"';
		if ($type == 'feeds') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Default Settings' ).'</a></li>';
			
		
		
		$tabs.=	'				</ul>
							<div class="clr"></div>
						</div>
					</div>
					<div class="clr"></div>';
		return $tabs;
  	}
	
	
}
?>